 package com.huawei.push.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.cloud.apigateway.sdk.utils.Client;
 import com.cloud.apigateway.sdk.utils.Request;
 import com.huawei.push.entity.SoftwareUsageInfo;
 import com.huawei.push.entity.Usage;
 import com.huawei.push.service.PushUsageInfoService;
 import com.huawei.push.util.SSLCipherSuiteUtil;
 import java.io.IOException;
 import java.util.ArrayList;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.util.EntityUtils;
 import org.springframework.stereotype.Service;
 
 @Service
 public class PushUsageInfoServiceImpl implements PushUsageInfoService {
   public String pushUsageInfo() throws IOException {
     String str = "";
     String url = "https://mkt.myhuaweicloud.com/api/mkp-openapi-public/global/v2/license/software-usage-info";
     Request request = new Request();
     request.setKey("HPUAJ1KBPW8C0TDRR0PX");
     request.setSecret("zEIyroEuXT7s01NWrb5yfH4iCHgXibJo5kSUeFtP");
     request.setMethod("POST");
     request.setUrl(url);
     request.addHeader("Content-Type", "application/json");
     Usage usage = new Usage();
     usage.setLicense("00039143-587a-4c7b-8ee8-fd0ae99d4745");
     ArrayList<SoftwareUsageInfo> softwareUsageInfoList = new ArrayList<>();
     SoftwareUsageInfo softwareUsageInfo = new SoftwareUsageInfo();
     softwareUsageInfo.setId("张三");
     SoftwareUsageInfo softwareUsageInfo2 = new SoftwareUsageInfo();
     softwareUsageInfo2.setId("李四");
     softwareUsageInfoList.add(softwareUsageInfo);
     softwareUsageInfoList.add(softwareUsageInfo2);
     usage.setSoftware_usage_Info(softwareUsageInfoList);
     ArrayList<Usage> usageList = new ArrayList<>();
     usageList.add(usage);
     JSONObject requestParam = new JSONObject();
     requestParam.put("usage_info", JSONArray.parseArray(JSON.toJSONString(usageList)));
     request.setBody(requestParam.toJSONString());
     System.out.println(requestParam.toJSONString());
     CloseableHttpClient client = null;
     try {
       HttpRequestBase signedRequest = Client.sign(request, "SDK-HMAC-SHA256");
       client = (CloseableHttpClient)SSLCipherSuiteUtil.createHttpClient("TLSv1.2");
       CloseableHttpResponse closeableHttpResponse = client.execute((HttpUriRequest)signedRequest);
       HttpEntity resEntity = closeableHttpResponse.getEntity();
       if (resEntity != null)
         str = EntityUtils.toString(resEntity, "UTF-8"); 
     } catch (Exception exception) {
     
     } finally {
       if (client != null)
         client.close(); 
     } 
     return str;
   }
 }
